package com.lnj.service;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.lnj.bean.model.Product;
import com.lnj.mapper.ProductMapper;
import dev.langchain4j.agent.tool.P;
import dev.langchain4j.agent.tool.Tool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.net.URI;
import java.net.URLEncoder;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;
import java.util.List;

/**
 * @program: AI_langchain4j
 * @description:
 * @author: zy
 * @create: 2025-07-01 11:39
 */
@Service
public class ToolServices {
    @Autowired
    private ProductMapper productMapper;

    @Tool("根据商品ID查询商品详细信息")
    public String getProductInfoById(Long productId) {
        // 实现查询商品详细信息的逻辑
        Product product = productMapper.selectById(productId);
        if (product == null) {
            return "商品ID: " + productId + " 不存在";
        }
        // 构建详细的商品信息字符串
        return String.format("""
                商品ID: %d
                名称: %s
                价格: %.2f
                描述: %s
                """,
                product.getProductId(),
                product.getProductName(),
                product.getPrice(),
                product.getDetail());
    }

}

